<template>
  <div class="app-container">
    <!-- 查询及添加 -->
    <el-form :inline="true" :model="formData" class="demo-form-inline">
      <el-form-item label = "状态:" style = "width:300px">
        <el-select v-model = "formData.warehouseOutStatus" placeholder = "请选择状态">
          <el-option
              v-for = "dict in warehouse_out_type"
              :label = "dict.label"
              :value = "dict.value"
              :key = "dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleQuery">搜索</el-button>
        <el-button @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 列表 -->
    <el-table :loading="loading" :data="tableData">
<!--      <el-table-column label="id" prop="warehouseOut.id" width="160" align="center"/>-->
      <el-table-column label="出库编号" prop="warehouseOut.warehouseOutNo" width="250" align="center"/>
      <el-table-column label="出库类型" prop="warehouseOut.goodsType" width="160" align="center">
        <template v-slot="scope">
          <dict-tag :options="warehouse_out_store_type" :value="scope.row.goodsType"/>
<!--          <el-tag v-if="scope.row.warehouseOut.goodsType === 2">销售出货检</el-tag>-->
        </template>
      </el-table-column>
      <el-table-column label="质检人" align="center" prop="userName" />
      <el-table-column label="质检时间" align="center" prop="qualityInspectionTime" width="180"/>
      <el-table-column label="质检类型" prop="qualityInspectionType" width="160" align="center">
        <template v-slot="scope">
          <!--<dict-tag :options="quality_inspection_type" :value="scope.row.qualityInspectionType"/>-->
          <el-tag v-if="scope.row.qualityInspectionType === 3">销售出货检</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="状态" prop="warehouseOut.warehouseOutStatus" width="160" align="center">
        <template v-slot="scope">
          <dict-tag :options="warehouse_out_type" :value="scope.row.warehouseOutStatus"/>
<!--          <el-tag type="success" v-if="scope.row.warehouseOut.warehouseOutStatus === 0">待检</el-tag>
          <el-tag type="warning" v-else-if="scope.row.warehouseOut.warehouseOutStatus === 1">待入库</el-tag>-->
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template v-slot="scope">
          <el-link
              :underline="false"
              icon="el-icon-edit"
              @click="quality(scope.row)"
              v-hasPermi="['quality:inspection:edit']"
          >质检</el-link>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="formData.pageNum"
        :limit.sync="formData.pageSize"
        @pagination="getList"
    />
    <Sales v-if="addDialog" v-model:addDialog="addDialog" @loadTableData="getList" :warehouseOutId="warehouseOutId" :goodsType="goodsType"/>
  </div>
</template>

<script setup>
  import {warehouseOutList} from "@/api/quality/quality.js";
  import {resetForm} from "@/utils/ruoyi.js";
  import Sales from "@/views/quality/OutboundInspection/Sales.vue";

  const { proxy } = getCurrentInstance();
  const { quality_inspection_type,warehouse_out_store_type,quality_inspection_status,warehouse_out_type } = proxy.useDict("quality_inspection_type","warehouse_out_store_type","quality_inspection_status","warehouse_out_type");

  // 遮罩层
  let loading = ref(true)
  // 总条数
  const total = ref(0)
  // 质检表格数据
  let tableData = ref([])
  // 查询参数
  let formData = reactive({
    pageNum: 1,
    pageSize: 10,
    goodsType: null,
    warehouseOutStatus: null
  })
  // 表单参数
  let form = ref({})

  let goodsType = ref()

  let addDialog = ref(false)

  function getList() {
    loading.value = true
    warehouseOutList(formData).then(response => {
      console.log(response.rows)

      tableData = response.rows
      total.value = response.total
      loading.value = false
    });
  }

  let warehouseOutId = ref()

  function quality(id){
    warehouseOutId.value = id.warehouseOut.id
    goodsType.value = id.warehouseOut.goodsType
    addDialog.value = true
  }

  // 表单重置
  function reset() {
    form = {
      id: null,
      qualityInspectionTime: null,
      userId: null,
      acceptance: null,
      disqualification: null,
      description: null,
      qualityInspectionType: null,
      warehouseInId: null,
      warehouseOutId: null
    }
    resetForm("form")
  }
  /** 搜索按钮操作 */
  function handleQuery() {
    formData.pageNum = 1
    getList()
  }
  /** 重置按钮操作 */
  function resetQuery() {
    formData.warehouseOutStatus = null
    getList();
  }
  getList()
</script>

<style scoped lang="scss">

</style>